/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.campusinfocompany.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lczyfz.campusinfo.modules.campusinfocompany.entity.CampusinfoCompany;
import com.lczyfz.campusinfo.modules.campusinfocompany.service.CampusinfoCompanyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.campusinfocompany.entity.CampusinfoConsist;
import com.lczyfz.campusinfo.modules.campusinfocompany.service.CampusinfoConsistService;

import java.util.List;

/**
 * 托管资金构成Controller
 * @author zms
 * @version 2018-05-07
 */
@Controller
@RequestMapping(value = "${adminPath}/campusinfocompany/campusinfoConsist")
public class CampusinfoConsistController extends BaseController {

	@Autowired
	private CampusinfoConsistService campusinfoConsistService;

	@Autowired
	private CampusinfoCompanyService campusinfoCompanyService;
	@ModelAttribute
	public CampusinfoConsist get(@RequestParam(required=false) String id) {
		CampusinfoConsist entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = campusinfoConsistService.get(id);
		}
		if (entity == null){
			entity = new CampusinfoConsist();
		}
		return entity;
	}
	
	@RequiresPermissions("campusinfocompany:campusinfoConsist:view")
	@RequestMapping(value = {"list", ""})
	public String list(CampusinfoConsist campusinfoConsist, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CampusinfoConsist> page = campusinfoConsistService.findPage(new Page<CampusinfoConsist>(request, response), campusinfoConsist);
		List<CampusinfoConsist> campusinfoConsists = campusinfoConsistService.findList(campusinfoConsist);
		model.addAttribute("campusinfoConsists", campusinfoConsists);
		model.addAttribute("page", page);
		return "modules/campusinfocompany/campusinfoConsistList";
	}

	@RequiresPermissions("campusinfocompany:campusinfoConsist:view")
	@RequestMapping(value = "form")
	public String form(CampusinfoConsist campusinfoConsist, Model model) {
		CampusinfoCompany campusinfoCompany = new CampusinfoCompany();
		List<CampusinfoCompany> campusinfoCompanies = campusinfoCompanyService.findList(campusinfoCompany);
		model.addAttribute("campusinfoCompanies",campusinfoCompanies);
		model.addAttribute("campusinfoConsist", campusinfoConsist);
		return "modules/campusinfocompany/campusinfoConsistForm";
	}

	@RequiresPermissions("campusinfocompany:campusinfoConsist:edit")
	@RequestMapping(value = "save")
	public String save(CampusinfoConsist campusinfoConsist, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, campusinfoConsist)){
			return form(campusinfoConsist, model);
		}
		campusinfoConsistService.save(campusinfoConsist);
		addMessage(redirectAttributes, "保存托管资金构成成功");
		return "redirect:"+Global.getAdminPath()+"/campusinfocompany/campusinfoConsist/?repage";
	}
	@RequiresPermissions("campusinfocompany:campusinfoConsist:view")
	@RequestMapping(value = "detail")
	public String detail(CampusinfoConsist campusinfoConsist, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CampusinfoConsist> page = campusinfoConsistService.findPage(new Page<CampusinfoConsist>(request, response), campusinfoConsist);
		model.addAttribute("page", page);
		return "modules/campusinfocompany/campusinfoConsistList";
	}
	@RequiresPermissions("campusinfocompany:campusinfoConsist:edit")
	@RequestMapping(value = "delete")
	public String delete(CampusinfoConsist campusinfoConsist, RedirectAttributes redirectAttributes) {
		campusinfoConsistService.delete(campusinfoConsist);
		addMessage(redirectAttributes, "删除托管资金构成成功");
		return "redirect:"+Global.getAdminPath()+"/campusinfocompany/campusinfoConsist/?repage";
	}

}